import 'package:dio/dio.dart';
import 'package:flutter_shensu/common/model/game.dart';

class NetWorkUtils {
  static NetWorkUtils _instance;

  static NetWorkUtils get instance {
    if (_instance == null) {
      _instance = NetWorkUtils._create();
    }
    return _instance;
  }

  NetWorkUtils._create() {}

  List<Game> _gameList = [];

  Future<List<Game>> getAllGameList() async {
    if (_gameList.length == 0) {
      var url = 'http://dl.js.ispeed.cn/Android/androidgamelist.json';
      var response = await Dio().get(url);
      if (response.statusCode == 200) {
        var resp = GameList.fromMap(response.data);
        _gameList = resp.game_list;
      }
    }
    return _gameList;
  }
}
